package com.study.boot.config;

import com.study.boot.factory.UserThreadFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author fangdengfu
 * @date 2020/7/4 9:51
 */
@Configuration
public class BeanConfig {

    @Bean
    public Executor taskExecutor() {
        return new ThreadPoolExecutor(
                // 核心线程数量
                2,
                // 最大线程数量
                4,
                // 保持活跃时间
                1000,
                // 时间单位
                TimeUnit.SECONDS,
                // 排队队列
                new ArrayBlockingQueue<>(5),
                // 自定义线程
                new UserThreadFactory("eventAysnc"));
    }
}
